#!/bin/bash

set -e

# 检查软链接是否存在，不存在则创建
checkAndLink() {
    local checkPath="$2"
    local linkPath="$1"

    if [ -L $checkPath ]; then
        # 是符号链接，删除
        rm $checkPath
    elif [ -e $checkPath ]; then
        # 其他类型文件，需要人工确认删除
        echo "Error: There is a file at the link destination:"
        echo "    $checkPath"
        echo "Please remove it manually."
        exit 1
    fi

    # 进行链接
    ln -s $linkPath $checkPath
}

checkAndLink /opt/starkylin_connectivity/daemon_test /usr/bin/daemon_test

# 修改权限以能执行
chmod +555 /opt/starkylin_connectivity/daemon_test
chmod +555 /usr/bin/daemon_test

systemctl daemon-reload
systemctl enable test.service
systemctl start test.service